package com.ymatou.iapi.csim.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.csim.parameter.GetAllBean;
import com.ymatou.iapi.csim.parameter.GetAllOnlinecsList.onlineCS;
import com.ymatou.iapi.csim.service.GetAllCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CsimCallService;
import com.ymttest.database.model.ymt_onlinecs;
import com.ymttest.database.sqlwapper.CSIM.ymt_cssessionWapper;
import com.ymttest.database.sqlwapper.CSIM.ymt_onlinecsWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
/**
*获取所有客服
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetAll{
	private static GetAllBean bean;
	private static GetAllCall call;
	private CsimCallService service=new CsimCallService();
	private Integer csId=Integer.parseInt(EnvSetup.getData("csId").toString());
	private static ymt_onlinecsWapper onlinecsWapper=new ymt_onlinecsWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取所有客服");
	}

	@Before
	public void caseUp() {
		bean=new GetAllBean();
		call=new GetAllCall();
		Logger.comment("删除历史数据");
		onlinecsWapper.deleteBy(MapUtil.hashMap("csId",csId,"Status",0));
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAll_1() {
		Logger.start(true,"获取所有客服-有客服存在");
		try {
			//客服上线
			service.getOnlineCS(csId);
			call.setData(bean);
			call.callService();	
			//验证返回值
			List<ymt_onlinecs>  onlinesLst=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",csId));
			List<onlineCS> onlineListCall=call.getResult().getResult();
			Logger.verifyEquals(true, onlineListCall.size()>0,"验证返回集合不为空");
			Logger.verifyEquals("200", call.getStatus(),"验证status");
			Logger.verifyEquals("", call.getMsg(),"验证Msg");
			for(int i=0;i<onlinesLst.size();i++)
			{
				Logger.verifyEquals(onlinesLst.get(i).getCSId(), onlineListCall.get(i).getCSId(),"验证CSId");
				Logger.verifyEquals(0, onlineListCall.get(i).getStatus(),"验证Status");
				Logger.verifyEquals(onlinesLst.get(i).getCSName(), onlineListCall.get(i).getCSName(),"验证CSName");
				Logger.verifyEquals(onlinesLst.get(i).getCSType(), onlineListCall.get(i).getCSType(),"验证CSType");
				Logger.verifyEquals(onlinesLst.get(i).getCurrentSessions(), onlineListCall.get(i).getCurrentSessions(),"验证CurrentSessions");
				Logger.verifyEquals(onlinesLst.get(i).getMaxSessions(), onlineListCall.get(i).getMaxSessionCount(),"验证MaxSessionCount");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAll_2() {
		Logger.start(true,"获取所有客服-客服离线");
		try {
			//客服上线
			ymt_onlinecs onlinecs=service.getOnlineCS(csId);
			onlinecs.setStatus(1);
			onlinecsWapper.updateByPrimaryKey(onlinecs);
			call.setData(bean);
			call.callService();	
			//验证返回值
			List<ymt_onlinecs>  onlinesLst=onlinecsWapper.selectBy(MapUtil.hashMap("CSId",csId));
			List<onlineCS> onlineListCall=call.getResult().getResult();
			Logger.verifyEquals("200", call.getStatus(),"验证status");
			Logger.verifyEquals("", call.getMsg(),"验证Msg");
			Logger.verifyEquals(true, onlineListCall.size()>0,"验证返回集合不为空");
			for(int i=0;i<onlinesLst.size();i++)
			{
				Logger.verifyEquals(onlinesLst.get(i).getCSId(), onlineListCall.get(i).getCSId(),"验证CSId");
				Logger.verifyEquals(1, onlineListCall.get(i).getStatus(),"验证Status");
				Logger.verifyEquals(onlinesLst.get(i).getCSName(), onlineListCall.get(i).getCSName(),"验证CSName");
				Logger.verifyEquals(onlinesLst.get(i).getCSType(), onlineListCall.get(i).getCSType(),"验证CSType");
				Logger.verifyEquals(onlinesLst.get(i).getCurrentSessions(), onlineListCall.get(i).getCurrentSessions(),"验证CurrentSessions");
				Logger.verifyEquals(onlinesLst.get(i).getMaxSessions(), onlineListCall.get(i).getMaxSessionCount(),"验证MaxSessionCount");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetAll_3() {
		Logger.start(true,"获取所有客服-客服不存在(ymt_onlinecs为空)");
		try {
			//客服上线
			//service.getOnlineCS(csId);
			onlinecsWapper.deleteBy(MapUtil.hashMap("csId",csId,"Status",0));
			call.setData(bean);
			call.callService();	
			//验证返回值
			List<onlineCS> onlineListCall=call.getResult().getResult();
			Logger.verifyEquals("200", call.getStatus(),"验证status");
			Logger.verifyEquals("", call.getMsg(),"验证Msg");
			Logger.verifyEquals(true, onlineListCall.size()==0,"验证返回集合为空");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}